package server;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author oyz
 * 从输入流中获取信息封装成request对象
 */
public class Request {

    private String url;

    private String method;

    private InputStream stream;

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public InputStream getStream() {
        return stream;
    }

    public void setStream(InputStream stream) {
        this.stream = stream;
    }

    public Request(InputStream stream) throws IOException {
        this.stream = stream;
        int count = 0;
        while(count==0){
            count = stream.available();
        }
        byte[] bytes = new byte[count];
        stream.read(bytes);
        String inputStr = new String(bytes);
        // 获取第一行请求头信息   GET / HTTP/1.1
        String firstLineStr = inputStr.split("\\n")[0];  // GET / HTTP/1.1

        String[] strings = firstLineStr.split(" ");
        this.method = strings[0];
        this.url = strings[1];
        System.err.println("=====>>method:" + method);
        System.err.println("=====>>url:" + url);


    }

    public Request() {
    }
}
